home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Toolkit / Multimedia Toolkit.iso / pascal / devadlib.pas < prev    next >
Pascal/Delphi Source File  |  1992-12-03  |  6KB  |  206 lines

  1. {****************************************************************************}
  2. {                                                                            }
  3. { MODULE:         DevAdLib                                                   }
  4. {                                                                            }
  5. { DESCRIPTION:    Device driver for the Adlib sound card and compatibles.    }
  6. {                 This works with Sound Blasters and with Covox SM II.       }
  7. {                 It uses timer polling.                                     }
  8. {                                                                            }
  9. { AUTHOR:         Juan Carlos Arévalo                                        }
  10. {                                                                            }
  11. { MODIFICATIONS:  Nobody (yet ;-)                                            }
  12. {                                                                            }
  13. { HISTORY:        12-Nov-1992 Description                                    }
  14. {                                                                            }
  15. { (C) 1992 VangeliSTeam                                                      }
  16. {____________________________________________________________________________}
  17.  
  18. UNIT DevAdLib;
  19.  
  20. INTERFACE
  21.  
  22.  
  23.  
  24.  
  25. { Device ID String. }
  26.  
  27. CONST
  28.   AdlibDevID = 'AdLib';
  29.  
  30.  
  31.  
  32.  
  33. IMPLEMENTATION
  34.  
  35. USES SoundDevices, StrConst;
  36.  
  37.  
  38.  
  39.  
  40. {----------------------------------------------------------------------------}
  41. { AdLib routines.                                                            }
  42. {____________________________________________________________________________}
  43.  
  44. PROCEDURE AdLibLoop; ASSEMBLER;
  45.   ASM
  46.  
  47. @@lp:           IN      AL,DX
  48.                 LOOP    @@lp
  49.  
  50.   END;
  51.  
  52.  
  53. PROCEDURE SendAdlibReg(Reg, Value: BYTE); ASSEMBLER;
  54.   ASM
  55.                 MOV     DX,$388
  56.                 MOV     AL,Reg
  57.                 OUT     DX,AL
  58.  
  59.                 MOV     CX,6
  60.                 CALL    AdLibLoop
  61.  
  62.                 INC     DX
  63.                 MOV     AL,Value
  64.                 OUT     DX,AL
  65.  
  66.                 MOV     CX,35
  67.                 CALL    AdLibLoop
  68.  
  69.   END;
  70.  
  71.  
  72. PROCEDURE ResetAdlib;
  73.   VAR
  74.     i : WORD;
  75.   BEGIN
  76.     FOR i := 1 TO 255 DO
  77.       SendAdlibReg(i, 0);
  78.   END;
  79.  
  80.  
  81.  
  82.  
  83. {----------------------------------------------------------------------------}
  84. { Assembler IRQ.                                                             }
  85. {____________________________________________________________________________}
  86.  
  87. {$L DEVADLIB}
  88.  
  89. PROCEDURE AdLibIntHandler; FAR; EXTERNAL;
  90.  
  91.  
  92.  
  93.  
  94. {----------------------------------------------------------------------------}
  95. { Name function.                                                             }
  96. {____________________________________________________________________________}
  97.  
  98. FUNCTION AdLibName : TDevName; FAR;
  99.   BEGIN
  100.     AdLibName := GetString(StrDevAdLibName);
  101.   END;
  102.  
  103.  
  104.  
  105.  
  106. {----------------------------------------------------------------------------}
  107. { Autodetect routine. It's always present. Well, it's not, but... O:-)       }
  108. {____________________________________________________________________________}
  109.  
  110. FUNCTION DevDetect : BOOLEAN; FAR;
  111.   BEGIN
  112.     DevDetect := TRUE;
  113.   END;
  114.  
  115.  
  116.  
  117.  
  118. {----------------------------------------------------------------------------}
  119. { Device Initialisation routine.                                             }
  120. {____________________________________________________________________________}
  121.  
  122. PROCEDURE DevInit(Hz: WORD); FAR; 
  123.   BEGIN
  124.     ResetAdlib;             { Turn off all channels, and stuff. }
  125.                             { Start in a known state.           }
  126.  
  127.     SendAdlibReg($01, $20);
  128.     SendAdlibReg($C0, $01);
  129.     SendAdlibReg($23, $27); { All this selects a sustained note, with a highest }
  130.     SendAdlibReg($43, $00); { pitch and with a fully rectified wave form.       }
  131.     SendAdlibReg($63, $FF); { Empirically calculated (trial and error). If you  }
  132.     SendAdlibReg($83, $0F); { can find a better configuration, please tell me.  }
  133.     SendAdlibReg($E3, $02);
  134.     SendAdlibReg($A0, $0C);
  135.     SendAdlibReg($B0, $3F);
  136.  
  137.     CalcTimerData(Hz);   { Then, standard pollin init. }
  138.     InitTimer;
  139.   END;
  140.  
  141.  
  142.  
  143.  
  144. {----------------------------------------------------------------------------}
  145. { Device deinitialisation routine.                                           }
  146. {____________________________________________________________________________}
  147.  
  148. PROCEDURE DevEnd; FAR;
  149.   BEGIN
  150.     ResetAdlib;
  151.   END;
  152.  
  153.  
  154.  
  155.  
  156. {----------------------------------------------------------------------------}
  157. { Accesory routines.                                                         }
  158. {____________________________________________________________________________}
  159.  
  160. PROCEDURE DevChgHz(Hz: WORD); FAR;
  161.   BEGIN
  162.     CalcTimerData(Hz);
  163.     InitTimer;
  164.   END;
  165.  
  166. PROCEDURE DevPoll; FAR;
  167.   BEGIN
  168.   END;
  169.  
  170.  
  171.  
  172.  
  173. {----------------------------------------------------------------------------}
  174. { Device record.                                                             }
  175. {____________________________________________________________________________}
  176.  
  177. CONST
  178.   AdLibData : TSoundDevice = (
  179.     DevID      : AdLibDevID;
  180.     DMA        : FALSE
  181.   );
  182.  
  183.  
  184.  
  185.  
  186. {----------------------------------------------------------------------------}
  187. { Init code.                                                                 }
  188. {____________________________________________________________________________}
  189.  
  190. BEGIN
  191.  
  192.   WITH AdLibData DO BEGIN
  193.     Name            := AdLibName;
  194.     AutoDetect      := DevDetect;
  195.     InitRut         := DevInit;
  196.     ChgHzProc       := DevChgHz;
  197.     GetRealFreqProc := GetRealFreq;
  198.     TimerHandler    := AdLibIntHandler;
  199.     PollRut         := DevPoll;
  200.     EndRut          := DevEnd;
  201.   END;
  202.  
  203.   InitDevice(@AdLibData);
  204.  
  205. END.
  206.